import ApiBalance from "@/api/balance";
import ByCell from "@/components/ui/ByCell";
import ByCellGroup from "@/components/ui/ByCellGroup";
import ByText from "@/components/ui/ByText";
import useFetch from "@/hooks/useFetch";

type ApplyDetailsItem = {
  BalanceApplyDetailId: number;
  BalanceConfigId: number;
  ConfigName: string;
  CreateDate: string;
  CreateUserId: number;
  CreateUserName: string;
  DefaultHighValue: number;
  DefaultLowValue: number;
  DefaultValue: string;
  EditDate: string;
  EditUserId: number;
  EditUserName: string;
  FormBalanceApplyId: number;
  Formula: string;
  FormulaValue: number;
  IsCheck: boolean;
  IsRequire: boolean;
  IsSection: boolean;
  Mark: string;
  NewFormulaValue: number;
  NewIsChecked: boolean;
  OrgCode: string;
  OrgName: string;
  Remark: string;
  State: number;
  [property: string]: any;
};

export default ({ intentCustomerId, onShowApplyBtn }: { intentCustomerId: number, onShowApplyBtn: (show: boolean) => void }) => {
  const { data } = useFetch<{
    isCanApply: boolean;
    details: ApplyDetailsItem[];
  }>(ApiBalance.applyDetails, {
    defaultParams: [{ intentCustomerId }],
    onSuccess(res) {
      onShowApplyBtn(res?.isCanApply)
    }
  });

  return (
    <>
      <ByCellGroup className="m-3">
        {data?.details?.map((item, index) => (
          <ByCell label={item.ConfigName} border={index !== 0} align="right">
            <ByText type={item.State === 1 ? "success" : "error"}>
              {item.State === 1 ? "通过" : "未通过"}
            </ByText>
          </ByCell>
        ))}
      </ByCellGroup>
    </>
  );
};
